
//初始化会诊信息显示区域
function initConInfoTable(conInfo){
	if(conInfo){
		$('#conInfo_table').find('span').each(function(index,item){
			var bindname = $(item).attr('bindname');
			if(bindname){
				$(item).html(transItemCode(bindname,conInfo[bindname]));
			}
		})
	}
}
//加载时间轴
function initTimeLine(timeline){
	$("#timeline").html(timeline);
	$("#zhushi").show();
}

//初始化表单项
function initConInfoForm(conInfo){
	$('#conInfoForm').validation();
	if(conInfo){
		$('#conInfoForm').bindData(conInfo);
		//初始化会诊类型下拉框
		genDictSelect('conTypeInfo','con_type',conInfo.con_type);
		genDictSelect('expectType','expect_type',conInfo.expect_type);
		genDictSelect('emergencyType','emergency',conInfo.emergency);
		//会诊类型下拉框联动
		conTypeChange();
		//初始化指定医院级拉框
		initAssignHosSel(conInfo.assign_hid,conInfo.assign_did,conInfo.assign_docid);
	}else{
		//初始化会诊类型下拉框
		genDictSelect('conTypeInfo','con_type','1');
		//期望会诊时段
		genDictSelect('expectType','expect_type','1');
		genDictSelect('emergencyType','emergency','1');
		//会诊类型下拉框联动
		conTypeChange();
		//初始化指定医院级拉框
		initAssignHosSel(null,null,null);
	}
	
	//会诊类型下拉框联动
	function conTypeChange(){
		$('#con_type').change(function(){
			var contype=$(this).children('option:selected').val();
			if(contype=='1'){
				$('#assign_doc_div').show();
			}else{
				$('#assign_doc_div').hide();
			}
		}).change();
	}

	//初始化指定医院级拉框
	function initAssignHosSel(defaultHosVal,defaultDeptsVal,defaultUserVal){
		$.getApiClient('/consultation/hospitals/assign').get().done(function(data){
			if(!data.payload){
				data.payload=[];
			}
		    multipleSelectData("assign_hos",[{"id": "", "hospital_name": "请选择"}].concat(data.payload), defaultHosVal, {valueAttr:'id', displayAttr:'hospital_name'},'请选择');
			$('#assign_hos').multipleSelect({width:'100%', single: true});
			
			//医院科室下拉框联动
			$('#assign_hos').change(function(){
				var hosid=$(this).children('option:selected').val();
				initAssignDeptSel(hosid,defaultDeptsVal,defaultUserVal);
			}).change();
		});
	}
	
	//初始化指定科室下拉框
	function initAssignDeptSel(hosId,defaultVal,defaultUserVal){
		if(hosId){
			$.getApiClient('/consultation/departments/assign').setQuery({hospital_id:hosId}).get().done(function(data){
				if(!data.payload){
					data.payload=[];
				}
			    multipleSelectData("assign_dept",[{"id": "", "department_name": "请选择"}].concat(data.payload), defaultVal, {valueAttr:'id', displayAttr:'department_name'},"请选择");
				$('#assign_dept').multipleSelect({width:'100%', single: true});
				
				//科室医生下拉框联动
				$('#assign_dept').change(function(){
					var deptId=$(this).children('option:selected').val();
					initAssignDocSel(deptId,defaultUserVal);
				}).change();
			});
		}else{
			multipleSelectData("assign_dept",[{"id": "", "department_name": "请选择"}], defaultVal, {valueAttr:'id', displayAttr:'department_name'},"请选择");
			$('#assign_dept').multipleSelect({width:'100%', single: true});
			
			//科室医生下拉框联动
			$('#assign_dept').change(function(){
				var deptId=$(this).children('option:selected').val();
				initAssignDocSel(deptId,defaultUserVal);
			}).change();
		}
	}
	
	//初始化指定医生下拉框
	function initAssignDocSel(deptId,defaultVal){
		if(deptId){
			$.getApiClient('/consultation/doctors/assign').setQuery({department_id:deptId}).get().done(function(data){
				if(!data.payload){
					data.payload=[];
				}
			    multipleSelectData("assign_doc",[{"id": "", "user_name": "请选择"}].concat(data.payload), defaultVal, {valueAttr:'id', displayAttr:'user_name'},"请选择");
				$('#assign_doc').multipleSelect({width:'100%', single: true});
			});
		}else{
			multipleSelectData("assign_doc",[{"id": "", "user_name": "请选择"}], defaultVal, {valueAttr:'id', displayAttr:'user_name'},"请选择");
			$('#assign_doc').multipleSelect({width:'100%', single: true});
		}
	}
}